## Math
### average
Returns the average of two or more numbers.
```javascript
const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
```
example
```javascript
average(...[1, 2, 3]); // 2
average(1, 2, 3); // 2
```

### averageBy
Returns the average of an array, after mapping each element to a value using the provided function.
```javascript
const averageBy = (arr, fn) =>
  arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
  arr.length;
```
example
```javascript
averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 5
averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 5
```

### clampNumber
Clamps num within the inclusive range specified by the boundary values a and b.
```javascript
const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
```
example
```javascript
clampNumber(2, 3, 5); // 3
clampNumber(1, -1, -5); // -1
```

### digitize
Converts a number to an array of digits.
```javascript
const digitize = n => [...`${n}`].map(i => parseInt(i));
```
example
```javascript
digitize(123); // [1, 2, 3]
```

### distance
Returns the distance between two points.
```javascript
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
```
example
```javascript
distance(1, 1, 2, 3); // 2.23606797749979
```

### factorial
Calculates the factorial of a number.
```javascript
const factorial = n =>
  n < 0
    ? (() => {
        throw new TypeError('Negative numbers are not allowed!');
      })()
    : n <= 1 ? 1 : n * factorial(n - 1);
```
example
```javascript
factorial(6); // 720
```

### fibonacci
Generates an array, containing the Fibonacci sequence, up until the nth term.
```javascript
const fibonacci = n =>
  Array.from({ length: n }).reduce(
    (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
    []
  );
```
fibonacci(6); // [0, 1, 1, 2, 3, 5]

### inRange
Checks if the given number falls within the given range.
```javascript
const inRange = (n, start, end = null) => {
  if (end && start > end) end = [start, (start = end)][0];
  return end == null ? n >= 0 && n < start : n >= start && n < end;
};
```
example
```javascript
inRange(3, 2, 5); // true
inRange(3, 4); // true
inRange(2, 3, 5); // false
inrange(3, 2); // false
```

### isDivisible
Checks if the first numeric argument is divisible by the second one.
```javascript
const isDivisible = (dividend, divisor) => dividend % divisor === 0;
```
example
```javascript
isDivisible(6, 3); // true
```

### isEven
Returns true if the given number is even, false otherwise
```javascript
const isEven = num => num % 2 === 0;
```
example
```javascript
isEven(3); // false
```

### maxBy
Returns the maximum value of an array, after mapping each element to a value using the provided function.
```javascript
const maxBy = (arr, fn) => Math.max(...arr.map(typeof fn === 'function' ? fn : val => val[fn]));
```
example
```javascript
maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 8
maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 8
```

### minBy
Returns the minimum value of an array, after mapping each element to a value using the provided function.
```javascript
const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : val => val[fn]));
```
example
```javascript
minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 2
minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 2
```

### round
Rounds a number to a specified amount of digits.
```javascript
const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
```
example
```javascript
round(1.005, 2); // 1.01
```

### sum
Returns the sum of two or more numbers/arrays.
```javascript
const sum = (...arr) => [...arr].reduce((acc, val) => acc + val, 0);
```
example
```javascript
sum(...[1, 2, 3, 4]); // 10
```

### sumBy
Returns the sum of an array, after mapping each element to a value using the provided function.
```javascript
const sumBy = (arr, fn) =>
  arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0);
```
example
```javascript
sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 20
sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 20
```